package com.db.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.db.pojo.Feedback;
import com.db.pojo.Odreceipt;
import com.db.pojo.StoreOdreceipt;
import com.db.service.FeedbackService;
import com.db.service.OdreceiptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @Autowired
    private RestTemplate restTemplate;//提供多种便捷访问远程http服务的方法，简单的restful服务模板

    private final String REST_URL_PREFIX = "http://127.0.0.1:8081";


    //反馈意见单增加
    @RequestMapping("/addFeedback")
    @ResponseBody
    public String FeedbackController(Feedback feedback){

        // 请求头设置,x-www-form-urlencoded格式的数据
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        //提交参数设置
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("nicakname",feedback.getNickname());
        map.add("contact",feedback.getContact());
        map.add("content",feedback.getContent());
        map.add("createdate",feedback.getCreatedate());
        // 组装请求体
        HttpEntity<MultiValueMap<String, String>> request =
                new HttpEntity<MultiValueMap<String, String>>(map, headers);
        return restTemplate.postForObject(REST_URL_PREFIX + "/Feedback/addFeedback", request,String.class);


    }


}
